
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;
import * as cc from "cc";
/**
 * Predefined variables
 * Name = VMDemoList
 * DateTime = Sat Mar 19 2022 10:56:21 GMT+0800 (中国标准时间)
 * Author = 272493431
 * FileBasename = VMDemoList.ts
 * FileBasenameNoExtension = VMDemoList
 * URL = db://assets/scripts/scene/VMDemo/VMDemoList.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */
 
@ccclass('VMDemoList')
export class VMDemoList extends Component {

    @property(cc.Label)
    item: cc.Label = null;

    @property(cc.ScrollView)
    scrollView: cc.ScrollView = null;

    start () {
    }

    onEnable(){
        this.item.node.removeFromParent();
        cc.assetManager.main.config.scenes.forEach((scene)=>{
            let url = scene.url;
            let scenename = cc.path.basename(url, '.scene');
            if(!scenename.startsWith("DemoVM")){
                return;
            }
            
            let newItem = cc.instantiate(this.item.node);
            newItem.getComponent(cc.Label).string = url;
            newItem.parent = this.scrollView.content;
            newItem.on(cc.Node.EventType.TOUCH_END,()=>{
                
                cc.director.loadScene(scenename);
            });
        });

    }
    
    onDisable(){

    }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/decorator.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
